#ifndef __NET_ADDRESS_H__
#define __NET_ADDRESS_H__

#include "net_platform.h"
#include <string>

using namespace std;

namespace wel
{
	class NET_LIBRARY CNetAddr
	{
	public:
		CNetAddr()
			:m_uPort(0)
		{

		}

		CNetAddr(string strAddress, UINT16 uPort)
			:m_strAddress(strAddress), m_uPort(uPort)
		{

		}

		CNetAddr(UINT uiAddress, UINT16 uPort)
			:m_uPort(uPort)
		{
			SetIntAddress( uiAddress );
		}

		inline void SetStrAddress(const string &strAddress);
		inline void SetIntAddress(const UINT uiAddress);
		inline void SetPort(UINT16 uPort);

		inline UINT  GetIntAddress() const;
		inline string  GetStrAddress() const;
		inline UINT16  GetPort()    const;
		inline void    Clear();

	protected:
		string  m_strAddress;
		UINT16  m_uPort;
	};

	//----------------------------impl----------------------------------

	inline void CNetAddr::SetStrAddress(const string &strAddress)
	{
		m_strAddress = strAddress;
	}

	inline void CNetAddr::SetIntAddress(const UINT uiAddress)
	{
		struct in_addr addr;  
		addr.s_addr = uiAddress;

		m_strAddress = ::inet_ntoa( addr );
	}

	inline void CNetAddr::SetPort(UINT16 uPort)
	{
		m_uPort = uPort;
	}

	inline string CNetAddr::GetStrAddress() const
	{
		return m_strAddress;
	}

	inline UINT CNetAddr::GetIntAddress() const
	{
		return ::inet_addr( m_strAddress.c_str() );
	}

	inline UINT16 CNetAddr::GetPort() const
	{
		return m_uPort;
	}

	inline void  CNetAddr::Clear()
	{
		m_uPort = 0;
		m_strAddress.clear();
	}
}//end namespace(wel)

#endif //__NET_ADDRESS_H__
